<#assign module="area"/>

<#macro padZero value>
    <#if value?length==1>
        0${value?if_exists}
    <#else>
        ${value?if_exists}
    </#if>
</#macro>
<@override name="header">
</@override>
<@override name="body">

    <div class="row">
        <div class="col-xs-12">
            <button id="add-new-area" class="pull-right btn btn-primary"><i class="icon-plus"></i>&nbsp;添加新收费标准</button>
        </div>
    </div>

    <div class="row query-pad">
        <div class="col-xs-3 input-query" style="width: 800px;padding: 0px;display: flex; align-items: center;justify-content: space-between;">
            <span>收费标准名称：</span>
            <input type="text" class="form-control form-contb" id="searchName" name="searchName" placeholder="请输入收费标准名称"/>
            <@shiro.isMainCompany>
                <#if companys?exists>
                    <span>所属公司：</span>
                    <select class="form-control" id="companyId" name="companyId" style="width: 200px;">
                        <option value="">--请选择要查询的公司--</option>
                        <#list companys as company>
                            <option value="${company.id}">${company.companyName}</option>
                        </#list>
                    </select>
                </#if>
            </@shiro.isMainCompany>
            <button id="searchButton" class="pull-right btn btn-primary">&nbsp;查询</button>
        </div>
    </div>

    <div class="row margin-top area_container">
        <#list arealist as area>
            <form action="${ctx}/area/save" class="form-horizontal" method="post">
                <input type="hidden" name="id" value="${area.id}">
                <div class="col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <span class="name_span">${area.name?if_exists}</span>
                            <input type="text" value="${area.name}" name="name" class="name_input" style="width:150px;display:none;" required/>
                            <button type="button" data="${area.id}" class="deleteArea pull-right button button-pill button-flat-caution button-tiny">
                                <span class="glyphicon glyphicon-remove"></span>&nbsp;删除
                            </button>
                            <button type="button"
                                    class="area-add pull-right button button-pill button-flat-action button-tiny">
                                <span class="glyphicon glyphicon-plus"></span>&nbsp;新增时间段
                            </button>
                            <button type="button"
                                    class="area-edit pull-right button button-pill button-flat-primary button-tiny">
                                <span class="glyphicon glyphicon-edit"></span>&nbsp;修改
                            </button>
                            <button type="button"
                                    class="area-save pull-right button button-pill button-flat button-tiny">
                                <span class="glyphicon glyphicon-floppy-disk"></span>&nbsp;保存
                            </button>
                        </div>
                        <div class="panel-body  time_panel_body">
                            <#if area.chargeStartTimes??>
                                <#list area.chargeStartTimes?sort_by("cost") as time>
                                    <div class="item-length">
                                        <div class="panel-group">
                                            <div class="panel panel-default">
                                                <div class="panel-heading">
                                                    <h4 class="panel-title">
                                                        <a data-toggle="collapse" href="#collapseOne_${time.id}">展开</a>
                                                        <span class="time_content">
					         	开始服务时间（
		                    	<span class="this_startHour"><@padZero time.startHour /></span>
		                    	<select name="chargeStartTimes[${time_index}].startHour" class="startHour_select bottom_border" style="display:none;">
									<#list 0..23 as t>
                                        <option value="${t}"
                                                <#if time.startHour == t>selected</#if>><@padZero t /></option>
                                    </#list>
								</select>
		                    	：
		                    	<span class="this_startMinute"><@padZero time.startMinute /></span>
		                    	<select name="chargeStartTimes[${time_index}].startMinute"
                                        class="startMinute_select bottom_border" style="display:none;">
									<#list 0..59 as t>
                                        <option value="${t}"
                                                <#if time.startMinute == t>selected</#if>><@padZero t /></option>
                                    </#list>
								</select>
		                    	-
		                    	<span class="this_endHour"><@padZero time.endHour /></span>
		                    	<select name="chargeStartTimes[${time_index}].endHour"
                                        class="endHour_select bottom_border" style="display:none;">
									<#list 0..23 as t>
                                        <option value="${t}"
                                                <#if time.endHour == t>selected</#if>><@padZero t /></option>
                                    </#list>
								</select>
		                    	：
		                    	<span class="this_endMinute"><@padZero time.endMinute /></span>
		                    	<select name="chargeStartTimes[${time_index}].endMinute"
                                        class="endMinute_select bottom_border" style="display:none;">
									<#list 0..59 as t>
                                        <option value="${t}"
                                                <#if time.endMinute == t>selected</#if>><@padZero t /></option>
                                    </#list>
								</select>
		                    	）
		                    	起步价<span class="this_cost">${time.cost}</span>
                                                            <input type="number" value="${time.cost}"
                                                                   name="chargeStartTimes[${time_index}].cost"
                                                                   data-name="chargeStartTimes[${time_index}]"
                                                                   class="cost_input bottom_border"
                                                                   style="width:60px;display:none;"
                                                                   required min="0"/>元</span>
                                                        <span class="time_button pull-right">
					      		<button type="button"
                                        class="pull-right btn btn-default btn-xs time_button_delete">删除</button>
					      		<button type="button"
                                        class="pull-right btn btn-default btn-xs time_button_edit">修改</button>
					      		<button type="button"
                                        class="pull-right btn btn-default btn-xs time_button_add">添加里程价格</button>
					      		<button type="button"
                                        class="pull-right btn btn-default btn-xs weight_button_add">添加重量价格</button>
					      	</span>
					      </h4>
					    </div>
					    
					    <div id="collapseOne_${time.id}" class="panel-collapse collapse in">
					      <div class="panel-body">
					      
					      
					      	<table class="table table-condensed table-bordered distance-table">
								<tr style="font-size:14px;">
									<th>开始里程(公里)</th>
									<th>结束里程(公里)</th>
									<th>增长价(元)</th>
									<th>操作</th>
								</tr>
								<#if time.chargeStartDistances??>
									<#assign distancelist=time.chargeStartDistances />
			  						<#list distancelist as distance>
				  						<tr class="distance_tr">
				  							<#if (distance_index==0)>
				  							<td><span>${distancelist[distance_index].startdistance}</span><input class="distance_td_distance_start" type="number" required  value="${distancelist[distance_index].startdistance}" style="display:none;" /></td>
				  							<#else>
				  							<td><span>${distancelist[distance_index-1].distance}</span><input class="distance_td_distance_start" type="number" required  value="${distancelist[distance_index-1].distance}" style="display:none;" /></td>
				  							</#if>
											<td><span>${distance.distance}</span><input class="distance_td_distance" type="number" required value="${distance.distance}" style="display:none;" /></td>
											<td><span>${distance.money}</span><input class="distance_td_money" type="number" required value="${distance.money}" style="display:none;" /></td>
											<td>
												<a href="javascript:;" class='distance_td_edit'>修改</a>
												<a href="javascript:;" class='distance_td_delete'>删除</a>
											</td>
										</tr>
									</#list>
            					</#if>
							</table>
							<hr/>



							<table class="table table-condensed table-bordered weight-table">
								<tr style="font-size:14px;">
									<th>开始重量(公斤)</th>
									<th>结束重量(公斤)</th>
									<th>增长价(元)</th>
									<th>操作</th>
								</tr>
								<#if time.chargeStartNewWeights??>
									<#assign weightlist=time.chargeStartNewWeights />
			  						<#list weightlist as weight>
				  						<tr class="weight_tr">
				  							<#if (weight_index==0)>
				  							<td>0</td>
				  							<#else>
				  							<td><span>${weightlist[weight_index-1].weight}</span><input class="weight_td_weight_start" type="number" required  value="${weightlist[weight_index-1].weight}" style="display:none;" /></td>
				  							</#if>
											<td><span>${weight.weight}</span><input class="weight_td_weight" type="number" required value="${weight.weight}" style="display:none;" /></td>
											<td><span>${weight.money}</span><input class="weight_td_money" type="number" required value="${weight.money}" style="display:none;" /></td>
											<td>
												<a href="javascript:;" class='weight_td_edit'>修改</a>
												<a href="javascript:;" class='weight_td_delete'>删除</a>
											</td>
										</tr>
									</#list>
            					</#if>
							</table>
							<hr/>


							<span class="time_content2">
								超过（<span class="this_qblc">${time.qblc}</span><input type="number" value="${time.qblc}" name="chargeStartTimes[${time_index}].qblc" class="qblc_input bottom_border" style="width:60px;display:none;" required min="0"/>公里）
		                    	以后每<span class="this_djglUnit">${time.djglUnit}</span><input type="number" value="${time.djglUnit}" name="chargeStartTimes[${time_index}].djglUnit" class="djglUnit_input bottom_border" style="width:60px;display:none;" required min="0"/>公里
<#--		                    	（不足<span class="this_djglThresholdt">${time.djglThresholdt}</span><input type="number" value="${time.djglThresholdt}" name="chargeStartTimes[${time_index}].djglThresholdt" class="djglThresholdt_input bottom_border" style="width:60px;display:none;" required min="0"/>公里不计费）-->
		                    	加收<span class="this_djglCost">${time.djglCost}</span><input type="number" value="${time.djglCost}" name="chargeStartTimes[${time_index}].djglCost" class="djglCost_input bottom_border" style="width:60px;display:none;" required min="0"/>元 ；
		                    	<p></p>
		                    	起步后<span class="this_qbsj">${time.qbsj}</span><input type="number" value="${time.qbsj}" name="chargeStartTimes[${time_index}].qbsj" class="qbsj_input bottom_border" style="width:60px;display:none;" required min="0"/>分钟内不收费，
		                    	以后每<span class="this_djsjUnit">${time.djsjUnit}</span><input type="number" value="${time.djsjUnit}" name="chargeStartTimes[${time_index}].djsjUnit" class="djsjUnit_input bottom_border" style="width:60px;display:none;" required min="0"/>分钟
<#--		                    	（不足<span class="this_djsjThresholdt">${time.djsjThresholdt}</span><input type="number" value="${time.djsjThresholdt}" name="chargeStartTimes[${time_index}].djsjThresholdt" class="djsjThresholdt_input bottom_border" style="width:60px;display:none;" required min="0"/>分钟不收费）-->
		                    	加收<span class="this_djsjCost">${time.djsjCost}</span><input type="number" value="${time.djsjCost}" name="chargeStartTimes[${time_index}].djsjCost" class="djsjCost_input bottom_border" style="width:60px;display:none;" required min="0"/>元 ；
		                    	<p></p>
		                    	免费等候<span class="this_mfdhsj">${time.mfdhsj}</span><input type="number" value="${time.mfdhsj}" name="chargeStartTimes[${time_index}].mfdhsj" class="mfdhsj_input bottom_border" style="width:60px;display:none;" required min="1"/>分钟，
		                    	到达则立即加收<span class="this_dhsjAtonceCost">${time.dhsjAtonceCost}</span><input type="number" value="${time.dhsjAtonceCost}" name="chargeStartTimes[${time_index}].dhsjAtonceCost" class="dhsjAtonceCost_input bottom_border" style="width:60px;display:none;" required min="0"/>元 ，
		                    	后每<span class="this_dhsjUnit">${time.dhsjUnit}</span><input type="number" value="${time.dhsjUnit}" name="chargeStartTimes[${time_index}].dhsjUnit" class="dhsjUnit_input bottom_border" style="width:60px;display:none;" required min="0"/>分钟
<#--		                    	（ 低于<span class="this_dhsjThresholdt">${time.dhsjThresholdt}</span><input type="number" value="${time.dhsjThresholdt}" name="chargeStartTimes[${time_index}].dhsjThresholdt" class="dhsjThresholdt_input bottom_border" style="width:60px;display:none;" required min="0"/>分钟不计费）-->
		                    	加收<span class="this_dhsjCost">${time.dhsjCost}</span><input type="number" value="${time.dhsjCost}" name="chargeStartTimes[${time_index}].dhsjCost" class="dhsjCost_input bottom_border" style="width:60px;display:none;" required min="0"/>元；
					      		<p></p>
					      		超过（<span class="this_cgzl">${time.cgzl}</span><input type="number" value="${time.cgzl}" name="chargeStartTimes[${time_index}].cgzl" class="cgzl_input bottom_border" style="width:60px;display:none;" required min="0"/>公斤）
		                    	以后每<span class="this_zlUnit">${time.zlUnit}</span><input type="number" value="${time.zlUnit}" name="chargeStartTimes[${time_index}].zlUnit" class="zlUnit_input bottom_border" style="width:60px;display:none;" required min="0"/>公斤
<#--		                    	（不足<span class="this_zlThresholdt">${time.zlThresholdt}</span><input type="number" value="${time.zlThresholdt}" name="chargeStartTimes[${time_index}].zlThresholdt" class="zlThresholdt_input bottom_border" style="width:60px;display:none;" required min="0"/>公斤不计费）-->
		                    	加收<span class="this_zlCost">${time.zlCost}</span><input type="number" value="${time.zlCost}" name="chargeStartTimes[${time_index}].zlCost" class="zlCost_input bottom_border" style="width:60px;display:none;" required min="0"/>元。
					      	</span>
                                                    </div>
                                                </div>

                                            </div>
                                        </div>

                                    </div>

                                </#list>
                            </#if>

                            <h4 class="text-primary">收费说明：</h4>
                            <p class="text-muted">
                                <span class="memo_span">${area.memo?if_exists}</span>
                                <textarea class="memo_textarea" cols="100" rows="5" style="display:none;"
                                          name="memo">${area.memo?if_exists}</textarea>
                            </p>
                        </div>
                    </div>
                </div>
            </form>
        </#list>
        <div style="text-align:center" id="NoData"></div>
    </div>

    <div id="item-hour-div-start" style="display:none;">
        <#list 0..23 as t>
            <option value="${t}"><@padZero t /></option>
        </#list>
    </div>
    <div id="item-minute-div-start" style="display:none;">
        <#list 0..59 as t>
            <option value="${t}"><@padZero t /></option>
        </#list>
    </div>
    <div id="item-hour-div-end" style="display:none;">
        <#list 0..23 as t>
            <#if t==23>
                <option value="${t}" selected="selected"><@padZero t /></option>
            <#else>
                <option value="${t}"><@padZero t /></option>
            </#if>
        </#list>
    </div>
    <div id="item-minute-div-end" style="display:none;">
        <#list 0..59 as t>
            <#if t==59>
                <option value="${t}" selected="selected"><@padZero t /></option>
            <#else>
                <option value="${t}"><@padZero t /></option>
            </#if>
        </#list>
    </div>

</@override>
<@override name="footer">
    <script src="${ctx}/assets/js/area.js"></script>

    <script type="text/javascript">
        <#if successMessage??>
        $.scojs_message("${successMessage}", $.scojs_message.TYPE_OK);
        </#if>
        <#if failureMessage??>
        $.scojs_message("${failureMessage}", $.scojs_message.TYPE_ERROR);
        </#if>

        var dv;
        var dvitem

        function deleteArea() {
            $.post('${ctx}/area/delete', {'id': dv}, function (data) {
                if (data.success) {
                    $.scojs_message('地区删除成功', $.scojs_message.TYPE_OK);
                    window.location = "${ctx}/area/list";//强制刷新
                } else {
                    $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
                }
            }, 'json');
        }

        function deleteAreaNew() {
            window.location = "${ctx}/area/list";//强制刷新
        }

        function deleteAreaItem() {
            $.post('${ctx}/area/deleteitem', {'id': dvitem}, function (data) {
                if (data.success) {
                    $.scojs_message('时间段删除成功', $.scojs_message.TYPE_OK);
                    window.location = "${ctx}/area/list";//强制刷新
                } else {
                    $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
                }
            }, 'json');
        }

        $(document).ready(function () {
            $(document).on('click', '.deleteArea', function () {
                dv = $(this).attr('data');
                var confirm = $.scojs_confirm({
                    content: "你真的要删除该计费规则吗？",
                    action: deleteArea
                });
                confirm.show();
            });

            $(document).on('click', '.deleteArea-item', function () {
                dvitem = $(this).attr('data');
                var confirm = $.scojs_confirm({
                    content: "你真的要删除该时间段吗？",
                    action: deleteAreaItem
                });
                confirm.show();
            });

            $(document).on('click', '.deleteArea-new', function () {
                dv = $(this).attr('data');
                var confirm = $.scojs_confirm({
                    content: "你真的要删除该计费规则吗？",
                    action: deleteAreaNew
                });
                confirm.show();
            });


        });
    </script>
</@override>
<@extends name="../layout.ftl"/>